package com.github;


import com.github.sub.env.EnvCreateCommander;
import com.github.sub.env.EnvCurrentCommander;
import com.github.sub.env.EnvShowCommander;

import java.util.*;


public class EnvCommander extends Common implements Commander {
    private static final Map<String, Commander> MAP = new HashMap<>();

    static {
        MAP.put("-c", new EnvCreateCommander());
        MAP.put("-cur", new EnvCurrentCommander());
        MAP.put("-show", new EnvShowCommander());
    }

    @Override
    public Object run(Map<String, String> command) {
        command.forEach((k, v) -> {
            Commander commander = MAP.get(k);
            if (commander == null) {
                System.out.println(k + notFound);
            } else {
                commander.run(command);
            }
        });
        return null;
    }


    //    @Override
//    public String operation(String key, String value) {
//        if (key.equals(BLANK) && value.equals(BLANK)) {
//            return BLANK;
//        }
//
//        String currentPath = currentPath();
//        String fileName = currentPath + PATH + env + File.separator;
//        if (key.equals("-c")) {
//            List<String> collect = Arrays.stream(value.split(" ")).collect(Collectors.toList());
//            tradition.outPutFile(collect.get(1).getBytes(), fileName, collect.get(0));
//            System.out.println("env -create hashcode is " + key.hashCode());
//        } else if (key.equals("-cur")) {
//            String[] list = tradition.list(currentPath + PATH + File.separator + env);
//            Optional<String> first = Arrays.stream(list).filter(n -> n.equals(value)).findFirst();
//            if (first.isPresent()) {
//                String read = read(new File(currentPath + PATH + File.separator + env + File.separator + value));
//                tradition.outPutFile((value + "=" + read).getBytes(), currentPath + PATH + CURRENT_PATH, CURRENT_PATH);
//                System.out.println("env -current  is " + value);
//            } else {
//                System.out.println("env -current    " + value + " path is not exits");
//            }
//
//        } else if (key.equals("-show")) {
//            System.out.println(read(new File(currentPath + PATH + current + File.separator + current)));
//        } else {
//            System.out.println("key " + notFound);
//        }
//        return BLANK;
//
//    }

//    public static void main(String[] args) {
//        EnvCommander envCommander = new EnvCommander();
//        envCommander.operation("-create", "pre http://localhost:8080//");
//        envCommander.operation("-current", "pre");
//    }
}
